package com.sx.zongzhi.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.ContactBean;

import java.util.List;

/**站内联系人
 * Created by admin on 2017/12/12.
 */

public class InsideContactAdapter extends BaseQuickAdapter<ContactBean,BaseViewHolder> {

    private Context context;

    public InsideContactAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<ContactBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final ContactBean item) {
        helper.setText(R.id.checkbox,item.getName());
        if (item.getPhone()!=null){
            helper.setText(R.id.tv_Phone,item.getPhone());
        }
        final ImageView imageView = helper.getView(R.id.iv_img);
        if (item.isSelect()){
            imageView.setImageResource(R.mipmap.img_selected);
        }else {
            imageView.setImageResource(R.mipmap.img_default);
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.isSelect()){
                    item.setSelect(false);
                    imageView.setImageResource(R.mipmap.img_default);
                }else {
                    item.setSelect(true);
                    imageView.setImageResource(R.mipmap.img_selected);
                }
            }
        });
    }

}
